package com.designMode.principle;

/**
 * depedence inversion 更倾向玩面向接口.下面就是经典案例.也属于利用接口传递依赖
 * 依赖传递有3
 * 1.接口传递
 * 2.cons传递
 * 3.setter传递.
 */
public class DepedenceInversion_03 {
	public static void main(String[] args) {
		new Person().usePhoneOrPc(new Phone());

		new PersonCons(new Pc()).usePhoneOrPc();
		PersonSetter personSetter = new PersonSetter();
		personSetter.setiMessage(new Pc());
		personSetter.usePhoneOrPc();
	}
}

interface IMessage {
	void messageInfo();
}

class Phone implements IMessage {
	@Override
	public void messageInfo() {
		System.out.println("phone read meaage");
	}
}

class Pc implements IMessage {
	@Override
	public void messageInfo() {
		System.out.println("pc read message");
	}
}

class Person {
	void usePhoneOrPc(IMessage iMessage) {
		iMessage.messageInfo();
	}
}

class PersonCons {
	private IMessage iMessage;

	//利用cons
	public PersonCons(IMessage iMessage) {
		this.iMessage = iMessage;
	}

	void usePhoneOrPc() {
		iMessage.messageInfo();
	}
}

class PersonSetter {
	private IMessage iMessage;

	//利用setter
	public void setiMessage(IMessage iMessage) {
		this.iMessage = iMessage;
	}

	void usePhoneOrPc() {
		iMessage.messageInfo();
	}
}